var errorSet = require("./errorSet");
var fs = require("./fs");
function JsonError(errorMsg){
	if (!(this instanceof JsonError)) {
		return new JsonError(errorMsg);
	}
	if (errorSet.hasOwnProperty(errorMsg)) {
		this.errorCode = errorSet[errorMsg];
	}else{
		//错误不存在，创建新的错误号，重写errorSet.json文件
		this.errorCode = errorSet[errorMsg] = ((Object.keys(errorSet).length+1)/100000).toString().substr(2);
		console.log(Object.keys(errorSet));
		fs.fs.writeFileSync("server/_include/errorSet.json",JSON.stringify(errorSet));
	}
	this.errorMsg = errorMsg;
	this.errorTime = +new Date;
};
JsonError.prototype = {
	toString:function(){
		return JSON.stringify(this);
	}
}
module.exports = JsonError;